package threaduse;

/**
 * @description:
 * @Author yyp
 * @time 2022/3/28
 */
public class Thread01 {
    public static void main(String[] args) {
        Cat cat = new Cat();//继承thread类
        cat.start();

        Dog dog = new Dog();//实现runnable接口
        Thread thread = new Thread(dog);
        thread.start();

        Dog dog1 = new Dog();//多线程执行
        Thread thread1 = new Thread(dog1);
        thread1.start();

    }
}

class Cat extends Thread {
    int times = 0;
    @Override
    public void run(){
        while(true){
            System.out.println("cat第"+times+"次循环");
            times++;
            try{
                Thread.sleep(1000);
            }catch (InterruptedException e){
                e.printStackTrace();
            }
            if(times == 10){
                break;
            }
        }
    }
}

class Dog implements Runnable {
    int times = 0;
    @Override
    public void run(){
        while(true){
            System.out.println("dog第"+times+"次循环");
            times++;
            try{
                Thread.sleep(1100);
            }catch (InterruptedException e){
                e.printStackTrace();
            }
            if(times == 10){
                break;
            }
        }
    }
}
